package com.eascs.admin.o2o.loan.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.dubbo.config.annotation.Service;
import com.eascs.admin.o2o.loan.dao.LoanapplyOpLogDao;
import com.eascs.admin.o2o.loan.entity.O2oLoanGsMainproductInfo;
import com.eascs.app.dao.PageResult;
import com.eascs.app.dao.SqlPageQuery;
import com.eascs.common.util.StringUtil;

@Service
public class O2oLoanGsMainProductService implements IO2oLoanGsScService<O2oLoanGsMainproductInfo>{

	@Autowired
	LoanapplyOpLogDao dao;
	
	@Override
	public int insertEntity(O2oLoanGsMainproductInfo t) {
		return dao.insert(t);
	}

	@Override
	public int updateEntity(O2oLoanGsMainproductInfo t) {
		return dao.updateById(t);
	}

	@Override
	public O2oLoanGsMainproductInfo getEntityById(String id) {
		return dao.getById(O2oLoanGsMainproductInfo.class, id);
	}
	
	public O2oLoanGsMainproductInfo getEntityByLoan(String loanapplyNo) {
		String sql = "select * from o2o_loan_gs_mainproduct_info where loanapply_no=?";
		return dao.findEntity(sql, O2oLoanGsMainproductInfo.class, loanapplyNo);
	}
	
	public int delete(String id){
		return dao.deleteById(O2oLoanGsMainproductInfo.class, id);
	}

	@Override
	public List<O2oLoanGsMainproductInfo> queryEntitys(O2oLoanGsMainproductInfo t) {
		return null;
	}
	
	public int queryEntitysSize(String loanapplyNo ) {
		String sql =  "select count(*) from o2o_loan_gs_mainproduct_info where loanapply_no=? ";
		return dao.findInteger(sql, loanapplyNo);
	}
	
	@Override
	public PageResult<Object[]> queryPage(O2oLoanGsMainproductInfo t, int pageSize, int pageIndex) {
		SqlPageQuery<Object[]> pageQuery = new SqlPageQuery<>(Object[].class, pageSize, pageIndex);
		String querySql = "select id,product_name,production_address,last_month_sale_num,loanapply_no from o2o_loan_gs_mainproduct_info where 1=1 ";
		if(StringUtil.isNotBlank(t.getLoanapplyNo())){
			querySql = querySql + " and loanapply_no=?";
			pageQuery.addParam(t.getLoanapplyNo());
		}
		pageQuery.setQuerySql(querySql);
		return dao.findDataWithPage(pageQuery);
	}

}
